/**
 * Copyright &copy; 2012-2015 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.soccer.cms.modules.cms.utils;

import java.util.List;

import com.google.common.collect.Lists;
import com.soccer.cms.common.utils.SpringContextHolder;
import com.soccer.cms.modules.cms.entity.Imageinfo;
import com.soccer.cms.modules.cms.entity.Recommen;
import com.soccer.cms.modules.cms.dao.RecommenDao;
import com.soccer.cms.modules.sys.entity.Dict;

/**
 * 推荐功能Utils
 * @author zouqh
 * @version 2015-05-28
 */
public class RecommenUtils {

	private static RecommenDao recommenDao = SpringContextHolder.getBean(RecommenDao.class);
	
	public static Recommen getRecommen(String id) {
		return recommenDao.get(id);
	}
	
	public static List<Recommen> getRecommenList() {
		List<Recommen> recommens = null;
		Recommen recommen = new Recommen();
		recommens = recommenDao.findList(recommen);
		if(recommens == null){
			recommens = Lists.newArrayList();
		}
		return recommens;
	}
	
	/**
	 * 设置推荐的图片类型
	 * @param recommen
	 * @param imagetypes
	 */
	public static void setRecommenImageInfo(Recommen recommen,String[] imagetypes){
		if(recommen.getImageinfoList().size()==0){
			for (String imagetype : imagetypes) {
				Imageinfo imageinfo = new Imageinfo();
				imageinfo.setImagetype(new Dict(imagetype));
				recommen.getImageinfoList().add(imageinfo);
			}
		}
	}
	
	/**
	 * 设置推荐的图片类型
	 * @param recommen
	 * @param imagetypes
	 */
	public static void setRecommenImageInfo(Recommen recommen,String imagetypes){
		setRecommenImageInfo(recommen, imagetypes.split(","));
	}
}